<%@ page import="controllers.SolutionConnect" %>
<%@ page import="models.SolutionSubmission" %>
<%@ page import="models.SolutionAdoption" %>
<%@ page import="java.text.*,java.util.*"%>
<%@ page import="java.util.HashMap" %>
<%@ page import="com.googlecode.objectify.Objectify" %>
<%@ page import="com.googlecode.objectify.ObjectifyService" %>
<%@ page import="com.googlecode.objectify.Query" %>
<%@ page import="controllers.CommonConnect"%>

<% 
    int i =0;
    long awd_id = 0;
    String optionName ="";
    SimpleDateFormat dt1 = new SimpleDateFormat("MM/dd/yyyy");
    Date today = new java.util.Date();
    String DisplayDate =  dt1.format(today);
    long optionValue =0;
    String user_email1 = (String) pageContext.getAttribute("USER_EMAILID", PageContext.PAGE_SCOPE);
    CommonConnect NOM = new CommonConnect();
    List<HashMap<String,Object>> rsArea = NOM.GetArea();
    List<HashMap<String,Object>> rsCustomerrsArea = NOM.getCustomer();
    List<HashMap<String,Object>> rsSite = NOM.GetLocation();
    
%>

<div id="lotusContent">
<div class="lotusLayout lotusHeader">
<!--<h1>Savvy Solutions</h1>
<div class="lotusDetails">The Global Operations Excellence collection of Savvy Solutions resulting in cost savings for the company</div>-->
</div>
<!-- View selector -->
<div class="lotusActionBar lotusBtnContainer">
<!-- Buttons -->
<!--<span class="lotusBtn lotusBtnAction lotusLeft">
<a href="/blogs/roller-ui/myblogs/newentry">New Entry</a>
</span>-->
</div>
<br>
 <script defer="defer">
	 /* jQuery(document).ready(function() 
    { 
         jQuery("#insured_list")
		.tablesorter({widthFixed: true, widgets: ['zebra']})
		.tablesorterPager({container: $("#pager")}); 
    } 
	);  */
</script>
    <br>
<table>
<tr>
<td colspan="3"><div style="font-size:10"><b>Filter By : </b></div></td>
</tr>
<tr>
<td> Customer : </td><td><select id="cmbCustomer"  class="text-edit">
<option>--Select Customer--</option>
<%
                        i = 0;
                        while ( i < rsCustomerrsArea.size() ) {
                        	optionName = (String) rsCustomerrsArea.get(i).get("CustName");
                    %>

                    <option value="<%=optionName%>"> <%=optionName%></option>
                    <%
                            i++;
                        }
                        optionName = "";
                    %>
</select></td>
 <td></td>
</tr>
<tr>
<td> Location : </td><td><select id="cmbLocation"  class="text-edit">
<option>--Select Location--</option>
<%
                        i = 0;
                        while ( i < rsSite.size() ) {
                            optionName = (String) rsSite.get(i).get("LocationName");
                    %>

                    <option value="<%=optionName%>"> <%=optionName%></option>
                    <%
                            i++;
                        }
                        optionName = "";
                    %>
</select> </td><td></td>
</tr>
<tr>
<td> Process : </td><td colspan="2"><select id="cmbProcessarea"  class="text-edit">
<option>--Select Process Area--</option>

<%
	                        i = 0;
	                        while ( i < rsArea.size() ) {
	                            optionName = (String) rsArea.get(i).get("AreaName");
	                    %>
	
	                    <option value="<%=optionName%>"> <%=optionName%></option>
	                    <%
	                            i++;
	                        }
	                        optionName = "";
%>                    
</select> </td>
</tr>
<td> Solution Type: </td><td><select id="cmbSolType"  class="text-edit">
<option>--Select Solution Type--</option>
<option>Kaizen</option>, <option>Six Sigma</option>, <option>Other</option></select> </td><td></td>
</tr>
<tr>
<td>Financial Benefit :</td><td><select id="cmbFinBenfit"  class="text-edit">
<option>--Select Financial Benefit--</option><option>Hard Savings</option>, <option>Cost Avoidance</option>, <option>Opportunity Costs</option></select></td><td></td>
</tr>
<tr>
<td>Achieved Benefit :</td><td><select id="cmbAchBenfit"  class="text-edit">
<option>--Select Achieved Benefit--</option><option>Safety</option>, <option>Quality</option>, <option>Order Lead Time</option>, <option>Customer satisfaction</option>, <option>Employee engagement</option></select></td><td></td>
</tr>
<tr>
<td style="vertical-align: bottom;"> Posted Date : </td><td>From:&nbsp;&nbsp;<input type="text" name="fromDt" width="2"> <A 
                        onmouseover="window.status='Click here to select date from calender';return true;" 
onclick='showCalendar(this, document.forms[0].fromDt, "mm/dd/yyyy","en",1)'
                        onmouseout="window.status='';return true;" href="javascript:;"><img src="/img/bx.gif" width="16" height="15" alt="Select Date" border="0"></a></td>
<td>To:&nbsp;&nbsp;<input type="text" name="toDt"><A 
                        onmouseover="window.status='Click here to select date from calender';return true;" 
onclick='showCalendar(this, document.forms[0].toDt, "mm/dd/yyyy","en",1)'
                        onmouseout="window .status='';return true;" href="javascript:;"><img src="/img/bx.gif" width="16" height="15" alt="Select Date" border="0"></a></td>
</tr>
<tr><td></td><td></td><td></td><td></td></tr>
<tr><td><span class="lotusBtn lotusBtnAction lotusLeft">
<a href="javascript:Searchdocs()"><b>Show</b></a>
</span></td>
<td colspan="2"><span class="lotusBtn lotusBtnAction lotusLeft">
<a href="javascript:ClearAll()"><b>Clear</b></a>
</span></td>
</tr>
</td></tr>
</table><br>
<table>
<tr>
<td id="ViewRes">
<%
	boolean qfound = false;
	boolean bCustomer = false;
	boolean bLocation = false;
	boolean bProcessarea = false;
	boolean bSolType = false;
	boolean bFinBenfit = false;
	boolean bAchBenfit = false;
	boolean bfromDt = false;
	boolean btoDt = false;
	long solID;
	String solCode ="";
	String solTitle = "";
	String solCustomer = "";
	String solLocation = "";
	String solProcessArea = "";
	String solType = "";
	Date solsubmittedON;
	Float annProdSavings;
	
	String cmbCustomer = request.getParameter("cmbCustomer");
	String cmbLocation = request.getParameter("cmbLocation");
	String cmbProcessarea = request.getParameter("cmbProcessarea");
	String cmbSolType = request.getParameter("cmbSolType");
	String cmbFinBenfit = request.getParameter("cmbFinBenfit");
	String cmbAchBenfit = request.getParameter("cmbAchBenfit");
	String fromDt = request.getParameter("fromDt");
	String toDt = request.getParameter("toDt");	
	if (cmbCustomer != null)
	{
		qfound = true;
		bCustomer = true;
	}
	if (cmbLocation != null)
	{
		qfound = true;
		bLocation = true;
	}
	if (cmbProcessarea != null)
	{
		qfound = true;
		bProcessarea = true;
	}
	if (cmbSolType != null)
	{
		qfound = true;
		bSolType = true;
	}
	if (cmbFinBenfit != null)
	{
		qfound = true;
		bFinBenfit = true;
	}
	if (cmbAchBenfit != null)
	{
		qfound = true;
		bAchBenfit = true;
	}
	if (fromDt != null)
	{
		qfound = true;
		bfromDt = true;
	}
	if (toDt != null)
	{
		qfound = true;
		btoDt = true;
	}

	Objectify ofy = ObjectifyService.begin();
	Query<SolutionSubmission> q = ofy.query(SolutionSubmission.class).filter("Status", "Shared");
	Query<SolutionAdoption> q2 = ofy.query(SolutionAdoption.class);
	if (bCustomer)
	{
		q.filter("Customer", cmbCustomer);
		q2.filter("Customer", cmbCustomer);
	}
	if (bLocation)
	{
		q.filter("Location", cmbLocation);
		q2.filter("Location", cmbLocation);
	}
	if (bProcessarea)
	{
		q.filter("processArea", cmbProcessarea.replace(" and ", "&"));
		q2.filter("processArea", cmbProcessarea.replace(" and ", "&"));
	}
	if (bSolType)
	{
		q.filter("solType", cmbSolType.toString().trim());
		q2.filter("solType", cmbSolType.toString().trim());
	}
	if (bFinBenfit)
	{
		if (cmbFinBenfit.toString().trim().equals("Hard Savings")) {
			q.filter("hasHardSavings", true);
			q2.filter("hasHardSavings", true);
		} else if (cmbFinBenfit.toString().trim().equals("Cost Avoidance")) {
			q.filter("hasCostAvoidance", true);
			q2.filter("hasCostAvoidance", true);
		} else if (cmbFinBenfit.toString().trim().equals("Cost Avoidance")) {
			q.filter("hasOppurtunityCost", true);
			q2.filter("hasOppurtunityCost", true);
		}		
	}
	if (bAchBenfit)
	{
		q.filter("achievedTypeDesc", cmbAchBenfit);
		q2.filter("achievedTypeDesc", cmbAchBenfit);
	}
	if (bfromDt)
	{
		Date fdate = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss", Locale.ENGLISH).parse(fromDt + " 00:00:01");
		q.filter("submittedON >=", fdate);
		q2.filter("submittedON >=", fdate);
	}
	if (btoDt)
	{
		Date tdate = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss", Locale.ENGLISH).parse(toDt + " 23:59:59");
		q.filter("submittedON <=", tdate);
		q2.filter("submittedON <=", tdate);
	}
%>
</div>

        <link href="/media/dataTables/demo_page.css" rel="stylesheet" type="text/css" />
        <link href="/media/dataTables/demo_table.css" rel="stylesheet" type="text/css" />
        <link href="/media/dataTables/demo_table_jui.css" rel="stylesheet" type="text/css" />
        <link href="/media/themes/base/jquery-ui.css" rel="stylesheet" type="text/css" media="all" />
        <link href="/media/themes/smoothness/jquery-ui-1.7.2.custom.css" rel="stylesheet" type="text/css" media="all" />
        <script src="/scripts/jquery.js" type="text/javascript"></script>
        <script src="/scripts/jquery.dataTables.min.js" type="text/javascript"></script>
        <script type="text/javascript">
        $(document).ready(function () {
            $("#sharesolution").dataTable({
                "sPaginationType": "full_numbers",
                "bJQueryUI": true
            });
            
            $("#adoptesolution").dataTable({
                "sPaginationType": "full_numbers",
                "bJQueryUI": true
            });           
        });
        </script>

 

<div id="dt_example">
    <div id="container">
        <div id="demo_jui">
      <b>Shared Solutions :</b>	
	<table cellpadding="0" cellspacing="0" border="0" class="display" id="sharesolution" onload="javascript:hideView()">
          <thead>
              <tr>
                        <th>SolutionID</th>
						<th>SolutionTitle</th>
						<th>Customer</th>
						<th>Location</th>
						<th>Process</th>
						<th>Solution Type</th>
						<th>Total Annual Savings</th>
						<th>Posted Date</th>	
              </tr>
          </thead>
          <tbody>
        	<% 
        	for (SolutionSubmission f : q.fetch()) {
        		solID = f.getSolID();
        		solCode = f.getSolCode();
        		solTitle = f.getTitle();
        		solCustomer = f.getCustomer();
        		solLocation = f.getLocation();
        		solProcessArea = f.getProcessArea();
        		solType = f.getSolType();
        		solsubmittedON = f.getSubmittedON();
        		annProdSavings = f.getAnnProdSavings();
			%>
		  <tr>
		    <td><a href="/modules/default/display-solution.jsp?sol_id=<%=solID%>"><%=solCode%></a></td>
		    <td><%=solTitle%></td>
		    <td><%=solCustomer%></td>
			<td><%=solLocation%></td>
			<td><%=solProcessArea%></td>
			<td><%=solType%></td>
			<td><%=annProdSavings%></td>
			<td><%=solsubmittedON%></td>
		   
		  </tr>
			<% 
			} 
			%>
          </tbody>
      </table>
      <b>Adopted Solutions :</b>	
	<table cellpadding="0" cellspacing="0" border="0" class="display" id="adoptesolution" onload="javascript:hideView()">
          <thead>
              <tr>
                        <th>SolutionID</th>
						<th>SolutionTitle</th>
						<th>Customer</th>
						<th>Location</th>
						<th>Process</th>
						<th>Solution Type</th>
						<th>Posted Date</th>	
              </tr>
          </thead>
          <tbody>
        	<% 
        	for (SolutionAdoption f2 : q2.fetch()) {
        		solID = f2.getSolID();
        		solCode = f2.getSolCode();
        		solTitle = f2.getSolTitle();
        		solCustomer = f2.getCustomer();
        		solLocation = f2.getLocation();
        		solProcessArea = f2.getProcessArea();
        		solType = f2.getSolType();
        		solsubmittedON = f2.getSubmittedON();
			%>
		  <tr>
		    <td><a href="/modules/default/display-solution.jsp?sol_id=<%=solID%>"><%=solCode%></a></td>
		    <td><%=solTitle%></td>
		    <td><%=solCustomer%></td>
			<td><%=solLocation%></td>
			<td><%=solProcessArea%></td>
			<td><%=solType%></td>
			<td><%=solsubmittedON%></td>
		   
		  </tr>
			<% 
			} 
			%>
          </tbody>
      </table>
	  </div>
    </div>
</div>
</td></tr>
<tr><td id="SearchRes">
<div id="filters" class="lotusPaging" style='display:block;font-size:10'></div>
<div id='srchResult' style='display:block;' >
</div>
</td></tr></table>
<br>
<div class="lotusActionBar lotusBtnContainer">
<!-- Buttons -->
</div></div>
<!--End of Lotus Content-->
</div>
<!--End of Lotus Main-->
</div>
<!-- Footer gets moved to within Frame div in weblog.vm so closing tags need to go in weblog.vm - MTodd November 1 2007 </body> </html> -->
</div>
</div>
<input name="SaveOptions" type="hidden" value="0">
<input name="HTTP_Cookie" type="hidden" value="totalDocsrecommsols=142; __utma=88700297.683723686.1339743676.1344559297.1345078055.34; __utmz=88700297.1339743676.1.1.utmccn=(direct)|utmcsr=(direct)|utmcmd=(none); redirectto=/global/collaboration/savvysol.nsf/frmHome%3Fopenform; DomAuthSessId=9CAC08D0FC1F96BD8D086F8636AAC44B">
<input name="Query_String" type="hidden" value="OpenView&amp;Start=1&amp;Count=10">
<input name="dbName" type="hidden" value="">
<input name="Position" type="hidden" value="">
<input name="noofrecords" type="hidden" value="1435">
<input name="docnum" type="hidden" value="1">
<input name="Query_String_Decoded" type="hidden" value="OpenView&amp;Start=1&amp;Count=10">
<input name="start" type="hidden" value="1">
<input name="count" type="hidden" value="10">
<input name="QuickSearch" type="hidden" value="0">
<input name="UserProfileInfo" type="hidden" value="">
<input name="txtProfileUNID" type="hidden" value="">
<input name="SearchQuery" type="hidden" value="Search...">